/********************************************************************
This file is part of the KDE project.

Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2014 Kai Uwe Broulik <kde@privat.broulik.de>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras

Item {
    id: main

    Plasmoid.switchWidth: units.gridUnit * 5
    Plasmoid.switchHeight: units.gridUnit * 5
    Plasmoid.status:/* clipboardSource.data["clipboard"]["empty"] ? PlasmaCore.Types.PassiveStatus :*/ PlasmaCore.Types.ActiveStatus
    Plasmoid.toolTipMainText: i18n("词典")
    Plasmoid.toolTipSubText: clipboardSource.data["clipboard"]["empty"] ? i18n(" ") : '搜索：'+clipboardSource.data["clipboard"]["current"]
    Plasmoid.toolTipTextFormat: Text.PlainText
    Plasmoid.icon: "accessories-dictionary"

    function action_configure() {
        clipboardSource.service("", "configureDict");
    }

    Component.onCompleted: {
        plasmoid.removeAction("configure");
    }

    PlasmaCore.DataSource {
        id: clipboardSource
        property bool editing: false;
        engine: "org.kde.plasma.clipboard"
        connectedSources: "clipboard"
        onNewData: {
//             console.log(clipboardSource.data["clipboard"]["current"])
        }
    }
    
//    Plasmoid.compactRepresentation: TextEdit {
//        text: "abc"
//    }

    Plasmoid.fullRepresentation: Item {
        id: dialogItem
        Layout.minimumWidth: units.gridUnit * 5
        Layout.minimumHeight: units.gridUnit * 5

        focus: true

        PlasmaCore.FrameSvgItem {
            id : listItemSvg
            imagePath: "widgets/listitem"
            prefix: "normal"
            visible: false
        }

        Keys.forwardTo: [stack.currentPage]

        PlasmaComponents.PageStack {
            id: stack
            anchors.fill: parent
            initialPage: DictPage {
                id: cli
                anchors.fill: parent
            }
        }
        onVisibleChanged:{
            if (visible) {
                cli.text = clipboardSource.data["clipboard"]["current"]
                cli.query(cli.text)
            }
        }
    }
}
